import 'package:chathouse/constant/my_color.dart';
import 'package:chathouse/model/privacy_bean.dart';
import 'package:chathouse/pages/login/my_web_view.dart';
import 'package:chathouse/util/log.dart';
import 'package:chathouse/widgets/base_appbar.dart';
import 'package:chathouse/widgets/form_widgets/form_widgets.dart';
import 'package:chathouse/widgets/my_drop_down_widget.dart';
import 'package:chathouse/widgets/my_input_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:chathouse/util/base_utils.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import '../../constant/app_constant.dart';
import '../../model/response_bean.dart';
import '../../public/Obj.dart';
import '../../util/font_utils.dart';
import '../../widgets/buttons_tabbar.dart';
import '../client/client_root_container.dart';
import 'package:chathouse/net/Net.dart';
import 'package:chathouse/net/Apis.dart';

import 'my_web_view_asset_html.dart';

//政策與隱私條款頁
class PrivacyPage extends StatefulWidget {
  int? initialIndex;

  PrivacyPage({Key? key, this.initialIndex}) : super(key: key);

  @override
  State<PrivacyPage> createState() => _PrivacyPageState();
}

class _PrivacyPageState extends State<PrivacyPage> {
  PrivacyBean? privacyBean;

  @override
  void initState() {
    super.initState();
    // getAgreeData();
    LogUtil.d("initStateinitStateinitState");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar(),
      body: Column(
        children: [
          Expanded(
              child: DefaultTabController(
            initialIndex: widget.initialIndex ?? 0,
            length: 2,
            child: Column(
              children: <Widget>[
                ButtonsTabBar(
                  labelStyle:
                      getTextStyle(16.sp, color: MyColors.gary_69157154),
                  unselectedLabelStyle:
                      getTextStyle(16.sp, color: MyColors.gary_124124124),
                  buttonMargin: EdgeInsets.zero,
                  contentPadding: EdgeInsets.only(left: 20.w, right: 20.w),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(14.w),
                          topRight: Radius.circular(14.w))),
                  unselectedDecoration: BoxDecoration(
                      color: MyColors.gary_210210210,
                      borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(14.w),
                          topRight: Radius.circular(14.w))),
                  tabs: const [
                    Tab(
                      text: "平台使用條款",
                    ),
                    Tab(
                      text: "私隱政策聲明",
                    ),
                  ],
                ).setContainer(
                    width: double.infinity,
                    color: MyColors.gary_232233237,
                    padding:
                        EdgeInsets.only(top: 8.w, left: 20.w, right: 20.w)),
                Expanded(
                  child: TabBarView(
                    children: <Widget>[
                      // privacyBean == null
                      //     ? Container()
                      //     : MyWebView(privacyBean?.userServicesAgreement ?? ""),
                      // privacyBean == null
                      //     ? Container()
                      //     : MyWebView(privacyBean?.privacyAgreement ?? ""),
                      MyWebViewAssetHtml('assets/user_services_agreement.html'),
                      MyWebViewAssetHtml('assets/privacy_agreement.html'),
                    ],
                    physics: const NeverScrollableScrollPhysics(),
                  ).setContainer(
                      margin:
                          EdgeInsets.only(left: 20.w, right: 20.w, top: 14.w),
                      decoration: BoxDecoration(
                          border: Border.all(
                              color: MyColors.gary_112112112, width: 1.w))),
                ),
              ],
            ),
          )),
          Row(
            children: [
              Expanded(
                  child:
                      FormWidgets.getTextButton("回上頁", MyColors.gary_165165165)
                          .setOnClickListener(() {
                Get.back();
              })),
              SizedBox(
                width: 18.w,
              ),
              Expanded(
                  child: FormWidgets.getTextButton(
                "同意及確認",
                AppConstant.userRole == UserRole.c
                    ? MyColors.red_2166474
                    : MyColors.green_69157154,
                // MyColors.green_69157154
              ).setOnClickListener(() {
                Get.back(result: true);
              }))
            ],
          ).setContainer(
              margin: EdgeInsets.only(
                  left: 20.w, right: 20.w, bottom: 32.w, top: 32.w)),
        ],
      ),
    );
  }

  void getAgreeData() async {
    PrivacyBeanTool result;
    Obj.showLoading();
    Apis.getPrivacy()
        .then((response) => {
              Obj.dismissLoading(),
              result = PrivacyBeanTool.fromJson(response?.data ?? {}),
              if (result.isRequestSuccess)
                {
                  setState(() {
                    privacyBean = result.data;
                  })
                }
            })
        .catchError((error) => {Obj.dismissLoading(), setState(() {})});
  }
}
